/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package viewer.mortgage;
/**
 *
 * @author karakots
 */

import java.awt.Graphics;
import java.awt.Point;
import javax.swing.ImageIcon;
import java.awt.Graphics2D;

import viewer.common.Trans2D;

public class MCMapObj {

   
    static int refDiameter = 12;
    private static String imagedir = "icons/";
    static ImageIcon blueSphere, redSphere, greenSphere, yellowSphere, purpleSphere12;
    static ImageIcon blueHouse, redHouse, greenHouse, yellowHouse;
    static ImageIcon redBank, greenBank, adaptBank;
    static ImageIcon redX, bankFail;
    static ImageIcon greenDiamond, whiteDiamond, redDiamond, blackDiamond, blueDiamond;
    static ImageIcon greenDiamond20, greenDiamond40, greenDiamond60, greenDiamond80;
    static ImageIcon exclaim, plus;

    protected Point loc;

    public enum IconColor {
        kBlue, kRed, kGreen, kYellow, kWhite, kBlack
    }

    // constructor
    public MCMapObj () {
        if (blueSphere == null)
            blueSphere = createImageIcon(imagedir + "blueDot20.png", "a blue dot");
        if (redSphere == null)
            redSphere = createImageIcon(imagedir + "orangeDot20.png", "a red dot");
        if (greenSphere == null)
            greenSphere = createImageIcon(imagedir + "greenDot20.png", "a green dot");
        if (yellowSphere == null)
            yellowSphere = createImageIcon(imagedir + "yellowDot20.png", "a yellow dot");
        if (blueHouse == null)
            blueHouse = createImageIcon(imagedir + "blueHouse20.png", "a blue house");
        if (redHouse == null)
            redHouse = createImageIcon(imagedir + "redHouse20.png", "a red house");
        if (greenHouse == null)
            greenHouse = createImageIcon(imagedir + "greenHouse20.png", "a green house");
        if (yellowHouse == null)
            yellowHouse = createImageIcon(imagedir + "yellowHouse20.png", "a yellow house");
        if (redBank == null)
            redBank = createImageIcon(imagedir + "redBank20.png", "a red bank");
        if (greenBank == null)
            greenBank = createImageIcon(imagedir + "greenBank20.png", "a green bank");
        if (adaptBank == null)
            adaptBank = createImageIcon(imagedir + "adaptBank20.png", "a green bank with a blue delta");
        if (redX == null)
            redX = createImageIcon(imagedir + "RedX.png", "a red X");
        if (bankFail == null)
            bankFail = createImageIcon(imagedir + "BankFail.png", "green bank with red X");
        if (greenDiamond == null)
            greenDiamond = createImageIcon(imagedir + "greenDiamond.png", "a green diamond");
        if (whiteDiamond == null)
            whiteDiamond = createImageIcon(imagedir + "whiteDiamond.png", "a white diamond");
        if (redDiamond == null)
            redDiamond = createImageIcon(imagedir + "redDiamond.png", "a red diamond");
        if (blackDiamond == null)
            blackDiamond = createImageIcon(imagedir + "blackDiamond.png", "a black diamond");
        if (blueDiamond == null)
            blueDiamond = createImageIcon(imagedir + "blueDiamond.png", "a black diamond");

        if (greenDiamond20 == null)
            greenDiamond20 = createImageIcon(imagedir + "greenDiamond20pct.png", "a green diamond 20%");
        if (greenDiamond40 == null)
            greenDiamond40 = createImageIcon(imagedir + "greenDiamond40pct.png", "a green diamond 40%");
        if (greenDiamond60 == null)
            greenDiamond60 = createImageIcon(imagedir + "greenDiamond60pct.png", "a green diamond 60%");
        if (greenDiamond80 == null)
            greenDiamond80 = createImageIcon(imagedir + "greenDiamond80pct.png", "a green diamond 80%");
        if (exclaim == null)
            exclaim = createImageIcon(imagedir + "exclaim.png", "exclamation mark");
        if (plus == null)
            plus = createImageIcon(imagedir + "plus.png", "plus sign");
        if (purpleSphere12 == null)
            purpleSphere12 = createImageIcon(imagedir + "smallPurpleCircle.png", "epurple shpere 12");
    }

    public void setMapImageRect(double x, double y, Trans2D trans) {
        Trans2D.Vec2D v = new Trans2D.Vec2D(x, y);

       loc  = trans.map(v);
    }
    
    protected ImageIcon createImageIcon(String path, String description) {
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
  
    public void drawSphere(Graphics g, double scale, IconColor sphereColor) {
        int x = loc.x;
        int y = loc.y;
        int size =  (int) (12/scale + 0.5);
        switch (sphereColor) {
            case kBlue:
                g.drawImage(blueSphere.getImage(), x, y, size, size, null);
                break;
            case kRed:
                g.drawImage(redSphere.getImage(), x, y, size, size, null);
                break;
            case kGreen:
                g.drawImage(greenSphere.getImage(), x, y, size, size, null);
                break;
            case kYellow:
                g.drawImage(yellowSphere.getImage(), x, y, size, size, null);
                break;
            default:
        }
    }

    public void drawHouse(java.awt.Graphics2D g, double scale, IconColor color) {

        int x = loc.x - 3;
        int y = loc.y - 5;
        int size =  (int) (20/scale + 0.5);

        switch (color) {
            case kBlue:
                g.drawImage(blueHouse.getImage(), x, y, size, size, null);
                break;
            case kRed:
                g.drawImage(redHouse.getImage(), x, y, size, size, null);
                break;
            case kGreen:
                g.drawImage(greenHouse.getImage(), x, y, size, size, null);
                break;
            case kYellow:
                g.drawImage(yellowHouse.getImage(), x, y, size, size, null);
                break;
            default:
                g.setColor(java.awt.Color.RED);
                g.drawRect(x, y, size, size);
        }
    }


    public void drawBank(Graphics g, double scale, IconColor color) {
        int x = loc.x;
        int y = loc.y;
        int size =  (int) (20/scale + 0.5);

        switch (color) {
            case kRed:
                g.drawImage(redBank.getImage(), x, y, size, size, null);
                break;
            case kGreen:
                g.drawImage(greenBank.getImage(), x, y, size, size, null);
                break;
            case kBlue:
                g.drawImage(adaptBank.getImage(), x, y, size, size, null);
                break;
            default:
        }
    }

    public void drawName(Graphics g, String name) {
        int x = loc.x;
        int y = loc.y;
        g.setColor(java.awt.Color.WHITE);
        int width = g.getFontMetrics().stringWidth(name);
        g.drawString(name, x - width/2, y+10);
    }

    public void drawExclaim(Graphics g, double scale) {
        int size =  (int) (12/scale + 0.5);
        int x = loc.x;
        int y = loc.y;
        g.drawImage(exclaim.getImage(), x, y, size, size, null);
    }

    public void drawBankFail(Graphics g, double scale) {
        int size =  (int) (20/scale + 0.5);
        int x = loc.x;
        int y = loc.y;
        g.drawImage(bankFail.getImage(), x, y, size, size, null);
    }



    public void drawPlus(Graphics g, double scale) {
        int size =  (int) (12/scale + 0.5);
        int x = loc.x;
        int y = loc.y;
        g.drawImage(plus.getImage(), x, y, size, size, null);
    }


    public void drawDiamond(Graphics g, double scale, IconColor color) {
        // draw to the right of the house
        int x = loc.x;
        int y = loc.y;
        int size =  (int) (12/scale + 0.5);

        switch (color) {
            case kWhite:
                g.drawImage(whiteDiamond.getImage(), x, y, size, size, null);
                break;
            case kRed:
                g.drawImage(redDiamond.getImage(), x, y, size, size, null);
                break;
            case kGreen:
                g.drawImage(greenDiamond.getImage(), x, y, size, size, null);
                break;
            case kBlack:
                g.drawImage(blackDiamond.getImage(), x, y, size, size, null);
                break;
       }
    }

    public void drawRenter(Graphics2D g, double scale) {
        int size =  (int) (12/scale + 0.5);
        int x = loc.x;
        int y = loc.y;

        g.drawImage(purpleSphere12.getImage(), x, y, size, size, null);
    }

    public void drawRedX(Graphics g, double scale) {
       int x = loc.x;
       int y = loc.y;
       int size =  (int) (20/scale + 0.5);
       g.drawImage(redX.getImage(), x, y, size, size,null);
    }

    public boolean checkHit(Point p, int size) {
        boolean selected;
        if (    loc.x < p.x &&
                loc.y < p.y &&
                p.x < loc.x + size &&
                p.y < loc.y + size   )
            selected = true;
        else
            selected = false;
        return selected;
    }

}
